package com.laputa.service.method.impl;

import com.laputa.model.City;
import com.laputa.model.manager.CityManager;
import com.laputa.model.manager.UserManager;
import com.laputa.dao.model.User;
import com.laputa.service.method.LoginService;
import com.laputa.service.model.MainFrameData;

public class LoginServiceImpl implements LoginService {

	private UserManager userManager;
	private CityManager cityManager;
	private MainFrameData mainFrameData;
	
	public void setUserManager(UserManager userManager){
		this.userManager = userManager;
	}
	
	public void setCityManager(CityManager cityManager){
		this.cityManager = cityManager;
	}
	
	public void setMainFrameData(MainFrameData mainFrameData){
		this.mainFrameData = mainFrameData;
	}
	
	public boolean validate(String name, String password){
		return userManager.validate(name, password);
	}
	
	public Long getUserID(String name) {
		return userManager.getUserID(name);
	}
	
	public MainFrameData getmainFrameData(String name) {
		User u = userManager.getUserByName(name);
		Long id = userManager.getUserID(name);
		City city = cityManager.getCityObject(u.getCity().toString(), id.toString());
		this.mainFrameData.setId(id);
		this.mainFrameData.setName(name);
		this.mainFrameData.setCity(city);
		this.mainFrameData.setMoney(u.getMoney());
		return this.mainFrameData;
	}
}

